package com.pactera.madp.cp.controller.sidebar.employee;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.emp.EmployeeCreateDoDTO;
import com.pactera.madp.cp.api.dto.emp.EmployeeDoUpdateDTO;
import com.pactera.madp.cp.api.vo.moments.ToDoListVO;
import com.pactera.madp.cp.service.EmployeeDoService;
import com.pactera.madp.cp.service.TaskPubService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CpEmployeeDo)表控制层
 *
 * @author yushen.qi
 * @since 2021-06-29 15:14:04
 */
@RestController
@RequestMapping("/employeedo")
@Api(value = "employeedo", tags = "客户动态-待办")
public class EmployeeDoController {

    @Resource
    private EmployeeDoService employeeDoService;
    @Resource
    private TaskPubService taskPubService;

    @SysLog("新增待办")
    @PostMapping
    @ApiOperation(value = "新增待办")
    public R save(@RequestBody EmployeeCreateDoDTO dto) {
       return employeeDoService.insert(dto);
    }

    @SysLog("删除待办")
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除待办")
    public R remove(@PathVariable Integer id) {
        return employeeDoService.removeById(id) ? R.ok("删除成功！") : R.failed("删除失败！");
    }

    @GetMapping("/page")
    @ApiOperation(value = "查询待办分页")
    public R listByPage(Page page, Integer state, String wxExternalUserid, String wxUserId) {
        return R.ok(employeeDoService.listByState(page, state, wxExternalUserid, wxUserId));
    }

    @GetMapping("/list-two")
    @ApiOperation(value = "查询待办列表-两条数据")
    public R listByList(String wxUserId) {
        return R.ok(employeeDoService.listByStateList(wxUserId));
    }

    @SysLog("更新待办")
    @PutMapping
    @ApiOperation(value = "更新待办")
    public R update(@RequestBody EmployeeDoUpdateDTO dto) {
       return employeeDoService.update(dto) ? R.ok("更新成功！") : R.failed("更新失败");
    }

    @SysLog("跟进待办")
    @GetMapping("/change/{id}/{state}")
    @ApiOperation(value = "跟进待办")
    public R changState(@PathVariable Integer id, @PathVariable Integer state) {
        employeeDoService.state(id, state);
        return R.ok();
    }

    @GetMapping("/task-do")
    @ApiOperation(value = "获客任务/朋友圈任务待办")
    public R<Page<ToDoListVO>> getToDoListTask(Page page, @RequestParam("wxUserId") String wxUserId,Integer status,Integer type){
        return R.ok(taskPubService.getToDoList(page,wxUserId,status,type));
    }

}
